﻿using System.Text.RegularExpressions;

namespace com.iot.core.ext
{
    public static class StringExt
    {
        public static string ToSnakeCase(this string input)
        {
            if (string.IsNullOrEmpty(input))
            {
                return input;
            }

            var startUnderscores = Regex.Match(input, @"^_+");
            return startUnderscores + Regex.Replace(input, @"([a-z0-9])([A-Z])", "$1_$2").ToLower();
        }

        public static string ToLowerCamelCase(this string str)
        {
            var firstChar = str[0];

            if (firstChar == char.ToLowerInvariant(firstChar))
            {
                return str;
            }

            var name = str.ToCharArray();
            name[0] = char.ToLowerInvariant(firstChar);

            return new String(name);
        }
        public static string ToUpperCamelCase(this string str)
        {
            var firstChar = str[0];

            if (firstChar == char.ToUpperInvariant(firstChar))
            {
                return str;
            }

            var name = str.ToCharArray();
            name[0] = char.ToUpperInvariant(firstChar);

            return new String(name);
        }

    }
}
